$(function() {
  $('#go-reg').on('click',function(){
    $('.dl-top').hide()
    $('.dl-bottom').show()
    console.log(1)
  })
  $('#go-login').on('click',function(){
    $('.dl-top').show()
    $('.dl-bottom').hide()
  })
    const form = layui.form
    form.verify({
      username: [/^[a-z0-9]{5,10}$/i,'用户名不能少于5大于10'],
      password: [/^\S{6,12}$/, '密码必须为6-12, 并且不能为空格!'],
      rpPassword:function(value){
        const pwb = $('.dl-bottom [name=password]').val()
        if(value !== pwb) {
          console.log(pwb)
          return '两次密码不相同'
        }
      }
    })
    const layer = layui.layer
    $('#reg-form').on('submit',function(){
      const data = form.val('reg-form')
      $.post('http://back.zeng.pub/event/api/reguser',data)
        .then(res => {
          if(res.status !== 0){
            return layer.msg(res.message || '注册失败')
          }
          layer.msg('注册成功')
          this.reset()
          $('#go-login').click()
        })
      return false
    })
    $('#login-form').on('submit',function(){
      const data = form.val('login-form')
      $.post('http://back.zeng.pub/event/api/login',data)
      .then(res => {
        if(res.status !== 0){
          return layer.msg(res.massage || '登录失败')
          }
          layer.msg('登录成功')
          localStorage.setItem('BIG_EVENT_TOKEN',res.token)
          location.href = 'index.html'
      })

      return false
       
    })
})
